<template>
  <div>
    <quill-editor
      v-model="content"
      ref="myQuillEditor"
      :options="editorOption"
      @blur="onEditorBlur($event)"
      @focus="onEditorFocus($event)"
      @change="onEditorChange($event)">
    </quill-editor>
    <el-button type="primary" @click="saveData">保存邮件签名</el-button>
  </div>
</template>

<script>

import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
export default {
  name: 'MailConfig',
  components: { quillEditor },
  data() {
    return {
      content: ``,
      editorOption: {}
    }
  },
  created() {
    this.getSetting('COMMON', 'MAILCONFIG')
  },
  methods: {
    onEditorReady(editor) { // 准备编辑器
    },
    onEditorBlur() {
    }, // 失去焦点事件
    onEditorFocus() {
    }, // 获得焦点事件
    onEditorChange() {
    }, // 内容改变事件
    getSetting (model, name) {
      this.$http.get('/frontend/api/setting/getSetting', { model: model, name: name }).then(res => {
        this.content = res.value
      }).catch(errer => {
        this.$message.error(errer.message)
      })
    },
    saveData () {
      this.$confirm('是否修改邮件签名?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          model: 'COMMON',
          name: 'MAILCONFIG',
          value: this.content
        }
        this.$http.post('/frontend/api/setting/saveMail', param).then(res => {
          this.$message.success('保存成功')
        }).catch(errer => {
          this.$message.error(errer.message)
        })
      }).catch(() => {
      })
    }
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill
    }
  }
}
</script>

<style scoped>
.ql-editor{
  min-height: 300px;
}
</style>
